package com.shali.cloud.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.shali.cloud.entity.User;

@RestController
public class MovieController {

	@Autowired
	private RestTemplate restTemplate;
	
	@GetMapping("/movie/{id}")
	@HystrixCommand(fallbackMethod = "findByIdDefault")
	public User findById(@PathVariable Long id) {
		
		//VIP(virtual IP) microservice-provider-user
		return this.restTemplate.getForObject("http://microservice-provider-user/findOne/"+id, User.class);
	}
	
	public User findByIdDefault(Long id) {
		User user = new User();
		user.setId(1L);
		return user;
	}
}
